Don't seed Registry with known source ids
authorAlex Crichton <alex@alexcrichton.com>
Wed, 22 Oct 2014 22:21:34 +0000 (15:21 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 27 Oct 2014 19:40:23 +0000 (12:40 -0700)
In the normal case this isn't necessary due to the Registry dynamically
discovering sources when dependencies are queried for. Consequently there's no
need to register all these sources ahead-of-time, and it reduces the cognitive
load when thinking about sources and updates.

src/cargo/core/manifest.rs
src/cargo/core/package.rs
src/cargo/ops/cargo_fetch.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/util/toml.rs

index 73c77be1c63f7f3793d1ecc92ad55e01c48af22d..4ef140b03663db011d93fefcd12c1d940b93b07c 100644 (file)
@@ -4,12 +4,7 @@ use std::fmt::{mod, Show, Formatter};
 use semver::Version;
 use serialize::{Encoder,Encodable};
 
-use core::source::SourceId;
-use core::{
-    Dependency,
-    PackageId,
-    Summary
-};
+use core::{Dependency, PackageId, Summary};
 use core::package_id::Metadata;
 use core::dependency::SerializedDependency;
 use util::{CargoResult, human};
@@ -21,7 +16,6 @@ pub struct Manifest {
     targets: Vec<Target>,
     target_dir: Path,
     doc_dir: Path,
-    sources: Vec<SourceId>,
     build: Vec<String>,
     warnings: Vec<String>,
     exclude: Vec<String>,
@@ -369,7 +363,7 @@ impl Show for Target {
 
 impl Manifest {
     pub fn new(summary: Summary, targets: Vec<Target>,
-               target_dir: Path, doc_dir: Path, sources: Vec<SourceId>,
+               target_dir: Path, doc_dir: Path,
                build: Vec<String>, exclude: Vec<String>,
                metadata: ManifestMetadata) -> Manifest {
         Manifest {
@@ -377,7 +371,6 @@ impl Manifest {
             targets: targets,
             target_dir: target_dir,
             doc_dir: doc_dir,
-            sources: sources,
             build: build,
             warnings: Vec::new(),
             exclude: exclude,
@@ -417,11 +410,6 @@ impl Manifest {
         &self.doc_dir
     }
 
-    /// Returns a list of all the potential `SourceId`s of the dependencies.
-    pub fn get_source_ids(&self) -> &[SourceId] {
-        self.sources.as_slice()
-    }
-
     pub fn get_build(&self) -> &[String] {
         self.build.as_slice()
     }
index a7ca094b12060c942429ae0422a33125abf9bf74..fa84b9c3bf88a1340e16a90f51829822e61c9182 100644 (file)
@@ -110,12 +110,6 @@ impl Package {
     pub fn get_absolute_target_dir(&self) -> Path {
         self.get_root().join(self.get_target_dir())
     }
-
-    pub fn get_source_ids(&self) -> Vec<SourceId> {
-        let mut ret = vec!(self.source_id.clone());
-        ret.push_all(self.manifest.get_source_ids());
-        ret
-    }
 }
 
 impl Show for Package {
index e2457bc5d9f668c666319eb75e33f439eb253b3d..054ef42893ceda185a9577648c7e0b242c9cf89a 100644 (file)
@@ -31,9 +31,9 @@ pub fn resolve_and_fetch(registry: &mut PackageRegistry, package: &Package)
     let lockfile = package.get_manifest_path().dir_path().join("Cargo.lock");
     let source_id = package.get_package_id().get_source_id();
     let previous_resolve = try!(ops::load_lockfile(&lockfile, source_id));
-    match previous_resolve {
+    let sources = match previous_resolve {
         Some(ref r) => r.iter().map(|p| p.get_source_id().clone()).collect(),
-        None => package.get_source_ids(),
+        None => vec![package.get_package_id().get_source_id().clone()],
     };
     try!(registry.add_sources(sources));
 
index 43be2d6e8206b45b26c50645870bfa30182397f0..5e11626c44a85bd03c7a75b245ae267baa12359e 100644 (file)
@@ -25,12 +25,10 @@ pub fn generate_lockfile(manifest_path: &Path,
     let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(source.update());
     let package = try!(source.get_root_package());
-    let source_ids = package.get_source_ids();
     let mut config = try!(Config::new(shell, None, None));
 
     let resolve = {
         let mut registry = PackageRegistry::new(&mut config);
-        try!(registry.add_sources(source_ids));
         try!(resolver::resolve(package.get_summary(),
                                resolver::ResolveEverything,
                                &mut registry))
@@ -83,7 +81,7 @@ pub fn update_lockfile(manifest_path: &Path,
                                   .filter(|s| !to_avoid.contains(s))
                                   .map(|s| s.clone()));
         }
-        None => sources.extend(package.get_source_ids().into_iter()),
+        None => {}
     }
     try!(registry.add_sources(sources));
 
index 5cb0082aa3c9c0b6aaced1705caa712c05e00356..465280331de56a987eb1f8b432e0cc0a430c79b8 100644 (file)
@@ -293,7 +293,6 @@ impl TomlProject {
 struct Context<'a> {
     deps: &'a mut Vec<Dependency>,
     source_id: &'a SourceId,
-    source_ids: &'a mut Vec<SourceId>,
     nested_paths: &'a mut Vec<Path>
 }
 
@@ -371,7 +370,6 @@ fn inferred_bench_targets(layout: &Layout) -> Vec<TomlTarget> {
 impl TomlManifest {
     pub fn to_manifest(&self, source_id: &SourceId, layout: &Layout)
         -> CargoResult<(Manifest, Vec<Path>)> {
-        let mut sources = vec!();
         let mut nested_paths = vec!();
 
         let project = self.project.as_ref().or_else(|| self.package.as_ref());
@@ -462,7 +460,6 @@ impl TomlManifest {
             let mut cx = Context {
                 deps: &mut deps,
                 source_id: source_id,
-                source_ids: &mut sources,
                 nested_paths: &mut nested_paths
             };
 
@@ -495,7 +492,6 @@ impl TomlManifest {
                                          targets,
                                          layout.root.join("target"),
                                          layout.root.join("doc"),
-                                         sources,
                                          build,
                                          exclude,
                                          metadata);
@@ -534,10 +530,7 @@ fn process_dependencies<'a>(cx: &mut Context<'a>, dev: bool,
                 let loc = try!(git.as_slice().to_url().map_err(|e| {
                     human(e)
                 }));
-                let source_id = SourceId::new(kind, loc);
-                // TODO: Don't do this for path
-                cx.source_ids.push(source_id.clone());
-                Some(source_id)
+                Some(SourceId::new(kind, loc))
             }
             None => {
                 details.path.as_ref().map(|path| {